#include"processpool.hpp"


void Usage(char * str)
{
    std::cout<<"Usage:"<<str<<" +num"<<std::endl;
}

using work_t=std::function<void()>;

void Work()
{
    //std::cout<<"hh"<<std::endl;
    // while(true)
    // {
    //     ;
    // }.
    while(true)
    {

        int task;
        int ret=::read(0,&task,sizeof(task));
        if(ret==sizeof(task))
        {
            tm.excute(task);
        }
        else if(ret==0)
        {
            break;
        }
    }
}


int main(int argc, char* argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        return UsageError;
    }
    int num=-std::stoi(argv[1]);//没加头文件string其他库可能也有这个函数实现所以没报错出来
    //cout<<num<<endl;
    processpool procp;
    procp.initprocesspool(num,Work);
    //std::cout<<ret<<std::endl;

    procp.dispatchtask(20);

    procp.cleanprocesspool();
    




    return 0;
}